package spittr.service;

import org.springframework.stereotype.Service;
import spittr.model.Spittle;

import java.util.ArrayList;
import java.util.List;
@Service
public class SpittleService {
    private static List<Spittle> spittleList = new ArrayList<>();
    static {
        for(int i=1; i <= 8; i++){
            spittleList.add(new Spittle(i, "HelloWorld"+i, "user"+i/2));
        }
    }

    public List<Spittle> getSpittleList(){
        return spittleList;
    }

    public List<Spittle> getSpittlesByAuthorName(String authorName){
        if(authorName == null) return null;
        List<Spittle> requestSpittleList = new ArrayList<>();
        for(Spittle s:spittleList){
            if(s.getAuthorName().equals(authorName)){
                requestSpittleList.add(s);
            }
        }
        return requestSpittleList;
    }
}
